ostbuild: Move autodiscover-meta to ostbuild executor
authorColin Walters <walters@verbum.org>
Fri, 23 Dec 2011 15:48:57 +0000 (10:48 -0500)
committerColin Walters <walters@verbum.org>
Fri, 23 Dec 2011 15:48:57 +0000 (10:48 -0500)
Makefile-ostbuild.am
src/ostbuild/ostbuild-autodiscover-meta [deleted file]
src/ostbuild/pyostbuild/builtin_autodiscover_meta.py [new file with mode: 0755]
src/ostbuild/pyostbuild/main.py

index 075886069526255b3cb1d0003d8ac3e7ff0e85bf..96b2e37612884b0e695fa686ee339f0f41a46103 100644 (file)
@@ -20,7 +20,6 @@ ostbuild: src/ostbuild/ostbuild.in Makefile
 bin_SCRIPTS += ostbuild 
 
 bin_SCRIPTS += \
-       src/ostbuild/ostbuild-autodiscover-meta \
        src/ostbuild/ostbuild-commit-artifacts \
        src/ostbuild/ostbuild-chroot-compile-one-impl \
        src/ostbuild/ostbuild-nice-and-log-output \
@@ -34,6 +33,7 @@ pyostbuild_PYTHON =                                   \
        src/ostbuild/pyostbuild/ostbuildlog.py          \
        src/ostbuild/pyostbuild/subprocess_helpers.py   \
        src/ostbuild/pyostbuild/builtin_compile_one.py  \
+       src/ostbuild/pyostbuild/builtin_autodiscover_meta.py    \
        $(NULL)
 
 bin_PROGRAMS += src/ostbuild/ostbuild-user-chroot
diff --git a/src/ostbuild/ostbuild-autodiscover-meta b/src/ostbuild/ostbuild-autodiscover-meta
deleted file mode 100755 (executable)
index 15f2311..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2011 Colin Walters <walters@verbum.org>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-
-import os,sys,re,subprocess,tempfile,shutil
-import argparse
-
-parser = argparse.ArgumentParser(description="Discover source metadata from current directory")
-parser.add_argument('--meta')
-
-args = parser.parse_args()
-
-AUTODISCOVERED_KEYS = {}
-KEYS = {}
-
-def _register_discover_func(key, func):
-    if key not in AUTODISCOVERED_KEYS:
-        AUTODISCOVERED_KEYS[key] = []
-    AUTODISCOVERED_KEYS[key].append(func)
-
-def _discover_name_from_cwd():
-    return os.path.basename(os.getcwd())
-_register_discover_func('NAME', _discover_name_from_cwd)
-
-def _discover_version_from_git():
-    if os.path.isdir('.git'):
-        try:
-            version = subprocess.check_output(['git', 'describe'])
-        except subprocess.CalledProcessError, e:
-            version = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
-        return version.strip()
-    return None
-_register_discover_func('VERSION', _discover_version_from_git)
-
-def _discover_branch_from_git():
-    if os.path.isdir('.git'):
-        try:
-            ref = subprocess.check_output(['git', 'symbolic-ref', 'HEAD'])
-            return ref.replace('refs/heads/', '').strip()
-        except subprocess.CalledProcessError, e:
-            return None
-    return None
-_register_discover_func('BRANCH', _discover_branch_from_git)
-
-if args.meta:
-    f = open(args.meta)
-    for line in f.readlines():
-        (k,v) = line.split('=', 1)
-        KEYS[k.strip()] = v.strip()
-    f.close()
-
-for (key,hooks) in AUTODISCOVERED_KEYS.iteritems():
-    if key in KEYS:
-        continue
-    for func in hooks:
-        value = func()
-
-        if value is None:
-            continue
-
-        KEYS[key] = value
-        break
-
-for (key,value) in KEYS.iteritems():
-    print "%s=%s" % (key, value)
-
diff --git a/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py b/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py
new file mode 100755 (executable)
index 0000000..6808024
--- /dev/null
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2011 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,re,subprocess,tempfile,shutil
+import argparse
+
+from . import builtins
+from .ostbuildlog import log, fatal
+
+class OstbuildAutodiscoverMeta(builtins.Builtin):
+    name = "autodiscover-meta"
+    short_description = "Extract metadata from the current source directory"
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(self.short_description)
+        parser.add_argument('--meta')
+
+        args = parser.parse_args(argv)
+
+        KEYS = {}
+        AUTODISCOVERED_KEYS = {}
+
+        def _register_discover_func(key, func):
+            if key not in AUTODISCOVERED_KEYS:
+                AUTODISCOVERED_KEYS[key] = []
+            AUTODISCOVERED_KEYS[key].append(func)
+
+        _register_discover_func('NAME', self._discover_name_from_cwd)
+        _register_discover_func('VERSION', self._discover_version_from_git)
+        _register_discover_func('BRANCH', self._discover_branch_from_git)
+
+        if args.meta:
+            f = open(args.meta)
+            for line in f.readlines():
+                (k,v) = line.split('=', 1)
+                KEYS[k.strip()] = v.strip()
+            f.close()
+            
+        for (key,hooks) in AUTODISCOVERED_KEYS.iteritems():
+            if key in KEYS:
+                continue
+            for func in hooks:
+                    value = func()
+            
+                    if value is None:
+                        continue
+            
+                    KEYS[key] = value
+                    break
+            
+        for (key,value) in KEYS.iteritems():
+            print "%s=%s" % (key, value)
+        
+    def _discover_name_from_cwd(self):
+        return os.path.basename(os.getcwd())
+        
+    def _discover_version_from_git(self):
+        if os.path.isdir('.git'):
+            try:
+                version = subprocess.check_output(['git', 'describe'])
+            except subprocess.CalledProcessError, e:
+                version = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
+            return version.strip()
+        return None
+        
+    def _discover_branch_from_git(self):
+        if os.path.isdir('.git'):
+            try:
+                ref = subprocess.check_output(['git', 'symbolic-ref', 'HEAD'])
+                return ref.replace('refs/heads/', '').strip()
+            except subprocess.CalledProcessError, e:
+                return None
+        return None
+    
+builtins.register(OstbuildAutodiscoverMeta)
index 916f6da06ffc8abb2e2d46b800f7f4683138e0bc..5cd5587e5434a66475df7f79c7c2dc4f7b387398 100755 (executable)
@@ -23,6 +23,7 @@ import argparse
 
 from . import builtins
 from . import builtin_compile_one
+from . import builtin_autodiscover_meta
 
 def usage(ecode):
     print "Builtins:"